using System;
using System.Collections.Generic;

namespace OffsetPath
{
    public class ClassN : OffsetProfilo2D
    {
        private ClassN aClassN;
        private ClassN bClassN;

        public ClassN()
        {
        }

        public ClassN(ClassN A_0)
        {
            this.MethodB(A_0);
        }

        public ClassN(OffsetProfilo2D A_0)
        {
            this.e();
            for (int i = 0; i < A_0.GetListaLineaArco().Count; i++)
            {
                if (A_0.GetListaLineaArco()[i] is ForseLineaClassA)
                {
                    base.GetListaLineaArco().Add(new ForseLineaClassA(A_0.GetListaLineaArco()[i] as ForseLineaClassA));
                }
                else
                {
                    var arco = A_0.GetListaLineaArco()[i] as ForseArco2ClassQ;
                    base.GetListaLineaArco().Add(new ForseLineaClassA(arco.GetLinea()));
                }
            }
            base.ab();
            base.y();
        }

        public ClassN(List<PuntoDueD> A_0, bool A_1)
        {
            this.aClassN = null;
            this.bClassN = null;
            this.MathodA1(A_0, A_1);
        }

        public void MathodA1(ClassG A_0)
        {
            ClassAq classAq = new ClassAq();
            this.MethodB(classAq);
            classAq.a(A_0);
        }

        public bool MathodA1(ClassN A_0)
        {
            this.e();
            ClassAq classAq = new ClassAq();
            A_0.MethodB(classAq);
            ClassAq aq2 = new ClassAq();
            aq2.b(classAq);
            return this.MathodA1(aq2, false);
        }

        public void MathodA1(List<ClassN> A_0)
        {
            if ((this.MethodC() != null) && (this.MethodB() != null))
            {
                this.MethodC().MathodA1(A_0);
                this.MethodB().MathodA1(A_0);
            }
            else
            {
                A_0.Add(this);
            }
        }

        public void MathodA1(OffsetProfilo2D A_0)
        {
            this.e();
            for (int i = 0; i < A_0.GetListaLineaArco().Count; i++)
            {
                if (A_0.GetListaLineaArco()[i] is ForseLineaClassA )
                {
                    base.GetListaLineaArco().Add(new ForseLineaClassA(A_0.GetListaLineaArco()[i] as ForseLineaClassA));
                }
            }
            base.ab();
            base.y();
        }

        public void MathodA1(List<PuntoDueD> A_0)
        {
            base.GetListaLineaArco().Clear();
            for (int i = 0; i < A_0.Count; i++)
            {
                int num2 = i + 1;
                if (num2 == A_0.Count)
                {
                    num2 = 0;
                }
                base.GetListaLineaArco().Add(new ForseLineaClassA(A_0[i], A_0[num2]));
            }
        }

        public void MathodA1(double A_0)
        {
            this.GetStartPoint(A_0, this.q());
        }

        private PuntoDueD MathodA1(int A_0)
        {
            if (base.GetListaLineaArco().Count == 0)
            {
                return new PuntoDueD();
            }
            return base.GetListaLineaArco()[A_0 % base.GetListaLineaArco().Count].h();
        }

        private bool MathodA1(ref int A_0)
        {
            for (int i = 0; i < base.GetListaLineaArco().Count; i++)
            {
                if (this.MethodB(i))
                {
                    A_0 = i;
                    return true;
                }
            }
            return false;
        }

        public void MathodA1(ForseLineaClassA A_0, ref double A_1)
        {
            if (base.GetListaLineaArco().Count != 0)
            {
                if (!this.t())
                {
                    ClassN classN = new ClassN();
                    classN.MathodA1(this);
                    classN.MathodA1(A_0, ref A_1);
                }
                else
                {
                    int num = 0;
                    int num2 = 0;
                    int num3 = 0;
                    int num4 = 0;
                    double b = base.GetListaLineaArco()[0].h().Y;
                    double num6 = b;
                    double num7 = base.GetListaLineaArco()[0].h().X;
                    double num8 = num7;
                    for (int i = 1; i < base.GetListaLineaArco().Count; i++)
                    {
                        PuntoDueD puntoDueD = base.GetListaLineaArco()[i].h();
                        if (puntoDueD.Y < b)
                        {
                            b = puntoDueD.Y;
                            num = i;
                        }
                        else if (puntoDueD.Y > num6)
                        {
                            num6 = puntoDueD.Y;
                            num2 = i;
                        }
                        if (puntoDueD.X < num7)
                        {
                            num7 = puntoDueD.X;
                            num3 = i;
                        }
                        else if (puntoDueD.X > num8)
                        {
                            num8 = puntoDueD.X;
                            num4 = i;
                        }
                    }
                    double num10 = 0.0;
                    double num11 = 1.7E+308;
                    var a = new ForseLineaClassA(base.GetListaLineaArco()[num].h(), new ClassAtPuntoIncrementale(-1.0, 0.0));
                    var a2 = new ForseLineaClassA(base.GetListaLineaArco()[num2].h(), new ClassAtPuntoIncrementale(1.0, 0.0));
                    var a3 = new ForseLineaClassA(base.GetListaLineaArco()[num3].h(), new ClassAtPuntoIncrementale(0.0, 1.0));
                    var a4 = new ForseLineaClassA(base.GetListaLineaArco()[num4].h(), new ClassAtPuntoIncrementale(0.0, -1.0));
                    while (num10 < ClassK.s)
                    {
                        double num12;
                        int count = base.GetListaLineaArco().Count;
                        double num14 = a.b.c((base.GetListaLineaArco()[num % count] as ForseLineaClassA).b);
                        double num15 = a2.b.c((base.GetListaLineaArco()[num2 % count] as ForseLineaClassA).b);
                        double num16 = a3.b.c((base.GetListaLineaArco()[num3 % count] as ForseLineaClassA).b);
                        double num17 = a4.b.c((base.GetListaLineaArco()[num4 % count] as ForseLineaClassA).b);
                        if (((num14 < num15) && (num14 < num16)) && (num14 < num17))
                        {
                            num12 = num14;
                            num++;
                            a.a = base.GetListaLineaArco()[num % base.GetListaLineaArco().Count].h();
                        }
                        else if ((num15 < num16) && (num15 < num17))
                        {
                            num12 = num15;
                            num2++;
                            a2.a = base.GetListaLineaArco()[num2 % base.GetListaLineaArco().Count].h();
                        }
                        else if (num16 < num17)
                        {
                            num12 = num16;
                            num3++;
                            a3.a = base.GetListaLineaArco()[num3 % base.GetListaLineaArco().Count].h();
                        }
                        else
                        {
                            num12 = num17;
                            num4++;
                            a4.a = base.GetListaLineaArco()[num4 % base.GetListaLineaArco().Count].h();
                        }
                        num10 += num12;
                        num12 -= 1E-08;
                        a.b.MethodB(num12);
                        a2.b.MethodB(num12);
                        a3.b.MethodB(num12);
                        a4.b.MethodB(num12);
                        double num18 = a.e(a2.a);
                        double num19 = a3.e(a4.a);
                        double num20 = num18 * num19;
                        if (num20 < num11)
                        {
                            num11 = num20;
                            A_0.c(a);
                            A_0.a.MethodA(a4);
                            A_0.b.MethodA(num19);
                            A_1 = num18;
                        }
                    }
                }
            }
        }

        public bool MathodA1(List<PuntoDueD> A_0, bool A_1)
        {
            this.aClassN = null;
            this.bClassN = null;
            if (A_0.Count < 3)
            {
                return false;
            }
            this.MathodA1(A_0);
            base.ab();
            if (!this.j())
            {
                base.aa();
            }
            base.y();
            if (A_1 && base.u())
            {
                return this.l();
            }
            return true;
        }

        public bool MathodA1(ClassN A_0, ClassAtPuntoIncrementale A_1)
        {
            if ((base.GetListaLineaArco().Count < 2) || (A_0.GetListaLineaArco().Count < 2))
            {
                return false;
            }
            if (!base.a.e(A_0.z()))
            {
                return false;
            }
            if ((this.MethodC() != null) && (this.MethodB() != null))
            {
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale();
                ClassAtPuntoIncrementale at2 = new ClassAtPuntoIncrementale();
                bool flag = this.MethodC().MathodA1(A_0, classAt);
                bool flag2 = this.MethodB().MathodA1(A_0, at2);
                if (flag && flag2)
                {
                    A_1.f(ClassAtPuntoIncrementale.MethodB(classAt, at2));
                }
                else if (flag)
                {
                    A_1.f(classAt);
                }
                else if (flag2)
                {
                    A_1.f(at2);
                }
                if (!flag)
                {
                    return flag2;
                }
                return true;
            }
            if ((A_0.MethodC() != null) && (A_0.MethodB() != null))
            {
                bool flag3 = A_0.MathodA1(this, A_1);
                if (flag3)
                {
                    A_1.d();
                }
                return flag3;
            }
            ClassAj classAj = new ClassAj();
            ClassAj aj2 = new ClassAj();
            var a = new ForseLineaClassA();
            bool flag4 = false;
            for (int i = 0; i < (base.GetListaLineaArco().Count + A_0.GetListaLineaArco().Count); i++)
            {
                if (i < base.GetListaLineaArco().Count)
                {
                    a.MethodA(this.MathodA1(i), this.MathodA1((int) (i + 1)));
                }
                else
                {
                    a.MethodA(A_0.MathodA1((int) (i - base.GetListaLineaArco().Count)), A_0.MathodA1((int) ((i - base.GetListaLineaArco().Count) + 1)));
                }
                a.b.MethodB();
                a.b.MethodA();
                this.l(a.b, classAj);
                A_0.l(a.b, aj2);
                if ((classAj.b < aj2.a) && (classAj.a > aj2.a))
                {
                    if (!flag4 || ((aj2.a - classAj.b) < A_1.c()))
                    {
                        A_1.f(a.b);
                        A_1.MethodA((double) (aj2.a - classAj.b));
                        A_1.d((double) 1.001);
                        flag4 = true;
                    }
                }
                else
                {
                    if ((aj2.b >= classAj.a) || (aj2.a <= classAj.a))
                    {
                        return false;
                    }
                    if (!flag4 || ((classAj.a - aj2.b) < A_1.c()))
                    {
                        A_1.f(a.b);
                        A_1.MethodA((double) (classAj.a - aj2.b));
                        A_1.d();
                        A_1.d((double) 1.001);
                        flag4 = true;
                    }
                }
            }
            return true;
        }

        public void MathodA1(double A_0, double A_1)
        {
            double num = A_0 * ClassK.u;
            int num2 = 0;
            if (base.GetListaLineaArco().Count >= 3)
            {
                int count = base.GetListaLineaArco().Count;
                int num4 = 0;
                while (num4 < count)
                {
                    ClasseBaseLineaArcoClassAf classAf = base.GetListaLineaArco()[num2 % base.GetListaLineaArco().Count];
                    ClasseBaseLineaArcoClassAf af2 = base.GetListaLineaArco()[(num2 + 1) % base.GetListaLineaArco().Count];
                    var a = new ForseLineaClassA(classAf.h(), classAf.i());
                    var a2 = new ForseLineaClassA(af2.h(), af2.i());
                    ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(a.b);
                    classAt.d();
                    double num5 = a2.b.c(classAt);
                    if ((num5 < num) || (num5 > (ClassK.ad - num)))
                    {
                        this.MathodA1(a.c(A_1), num2 + 1);
                        this.MathodA1(num2 + 2, a2.c((double) (1.0 - A_1)));
                        count++;
                        num2 += 2;
                        num4 = 0;
                    }
                    else
                    {
                        num2++;
                        num4++;
                    }
                    if (num2 >= count)
                    {
                        num2 = 0;
                    }
                }
                base.y();
                if ((this.MethodC() != null) && (this.MethodB() != null))
                {
                    this.r();
                }
            }
        }

        private void MathodA1(int A_0, int A_1)
        {
            PuntoDueD puntoDueD = this.MathodA1(A_0);
            this.MathodA1(this.MathodA1(A_1), A_0);
            this.MathodA1(puntoDueD, A_1);
        }

        private void MathodA1(int A_0, PuntoDueD A_1)
        {
            A_0 = A_0 % base.GetListaLineaArco().Count;
            int num = 0;
            if (A_0 == 0)
            {
                num = base.GetListaLineaArco().Count - 1;
            }
            else
            {
                num = A_0 - 1;
            }
            int count = base.GetListaLineaArco().Count;
            var item = new ForseLineaClassA(A_1, base.GetListaLineaArco()[A_0].h());
            ClassAb classAb = new ClassAb();
            item.f(classAb);
            ClasseBaseLineaArcoClassAf classAf = base.GetListaLineaArco()[num];
            if (classAf is ForseLineaClassA)
            {
                var a2 = classAf as ForseLineaClassA;
                a2.d(A_1);
                a2.f(base.w()[num]);
                base.GetListaLineaArco().Insert(A_0, item);
                base.w().Insert(A_0, classAb);
            }
        }

        private void MathodA1(PuntoDueD A_0, int A_1)
        {
            int num;
            int num2;
            if (A_1 >= base.GetListaLineaArco().Count)
            {
                A_1 -= base.GetListaLineaArco().Count;
            }
            if (A_1 == 0)
            {
                num = base.GetListaLineaArco().Count - 1;
            }
            else
            {
                num = A_1 - 1;
            }
            if (A_1 == (base.GetListaLineaArco().Count - 1))
            {
                num2 = 0;
            }
            else
            {
                num2 = A_1 + 1;
            }
            ClasseBaseLineaArcoClassAf classAf = base.GetListaLineaArco()[A_1];
            if (classAf is ForseLineaClassA)
            {
                var a = classAf as ForseLineaClassA;
                a.MethodA(A_0, base.GetListaLineaArco()[num2].h());
                a.f(base.w()[A_1]);
                ClasseBaseLineaArcoClassAf af2 = base.GetListaLineaArco()[num];
                if (af2 is ForseLineaClassA)
                {
                    var a2 = af2 as ForseLineaClassA;
                    a2.d(A_0);
                    a2.f(base.w()[num]);
                }
            }
        }

        public bool MathodA1(ClassAb A_0, int A_1, int A_2)
        {
            this.e();
            if (A_1 < 3)
            {
                return false;
            }
            if (A_1 > A_2)
            {
                return false;
            }
            int num = new ClassAm((double) A_1, (double) A_2).d();
            PuntoDueD puntoDueD = new PuntoDueD();
            ClassAm classAm = new ClassAm(A_0.GetEndPnt().X, A_0.GetStartPoint().X);
            ClassAm am2 = new ClassAm(A_0.GetStartPoint().Y, A_0.GetEndPnt().Y);
            ClassAq classAq = new ClassAq();
            for (int i = 0; i < num; i++)
            {
                puntoDueD.X = classAm.MethodA();
                puntoDueD.Y = am2.MethodA();
                classAq.a(puntoDueD);
            }
            return this.MathodA1(classAq, true);
        }

        public bool MathodA1(ClassN A_0, ClassN A_1, double A_2)
        {
            int count = A_0.c.Count;
            int num2 = A_1.c.Count;
            if ((num2 < 3) || (count < 3))
            {
                return false;
            }
            if (count > num2)
            {
                return this.MathodA1(A_1, A_0, 1.0 - A_2);
            }
            ClassAq classAq = new ClassAq();
            int num3 = A_0.p();
            for (int i = 0; i < A_0.GetListaLineaArco().Count; i++)
            {
                PuntoDueD item = new PuntoDueD();
                item.e(A_0.GetListaLineaArco()[(i + num3) % A_0.GetListaLineaArco().Count].h());
                classAq.Add(item);
            }
            int num5 = num2 - count;
            int num6 = 0;
            int num7 = 0;
            while (num6 < num5)
            {
                var a = new ForseLineaClassA(classAq[num7], classAq[num7 + 1]);
                PuntoDueD x2 = new PuntoDueD();
                x2 = a.p();
                classAq.Insert(num7 + 1, x2);
                num7 += 2;
                num6++;
                if (num7 > (classAq.Count - 2))
                {
                    num7 = 0;
                }
            }
            int num8 = A_1.p();
            for (int j = 0; j < num2; j++)
            {
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(classAq[j], A_1.GetListaLineaArco()[(num8 + j) % A_1.GetListaLineaArco().Count].h());
                classAt.d(A_2);
                classAq[j].p(classAt);
            }
            return this.MathodA1(classAq, false);
        }

        public void MathodA1(ClassN A_0, List<ClassC> A_1, ClassAg A_2)
        {
            List<PolygonalShape> list = new List<PolygonalShape>();
            base.MethodA(A_0, list, A_2);
            for (int i = 0; i < list.Count; i++)
            {
                A_1.Add(new ClassC(list[i]));
            }
        }

        public bool MathodA1(PuntoDueD A_0, double A_1, int A_2)
        {
            this.e();
            if ((A_1 == 0.0) || (A_2 < 3))
            {
                return false;
            }
            double num = ClassK.ad / ((double) A_2);
            ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(0.0, A_1);
            var a = new ForseLineaClassA(A_0, classAt);
            ClassAq classAq = new ClassAq();
            for (int i = 0; i < A_2; i++)
            {
                PuntoDueD item = new PuntoDueD();
                item.e(a.i());
                classAq.Add(item);
                a.b.MethodB(num);
            }
            return this.MathodA1(classAq, false);
        }

        public bool MathodA1(ClassN A_0, ref double A_1, PuntoDueD A_2, PuntoDueD A_3)
        {
            ClassAb classAb = A_0.z();
            if (!base.z().MethodB(classAb))
            {
                return false;
            }
            int count = base.GetListaLineaArco().Count;
            if (count != base.w().Count)
            {
                return false;
            }
            int num2 = A_0.GetListaLineaArco().Count;
            if (num2 != A_0.w().Count)
            {
                return false;
            }
            List<ClassN.b> list = new List<ClassN.b>();
            for (int i = 0; i < count; i++)
            {
                if (base.w()[i].MethodB(classAb))
                {
                    ClassN.b item = new ClassN.b {
                                           b1 = base.GetListaLineaArco()[i] as ForseLineaClassA,
                                           c = base.w()[i],
                                           a = true
                                       };
                    list.Add(item);
                }
            }
            for (int j = 0; j < num2; j++)
            {
                if (A_0.w()[j].i(base.z()))
                {
                    ClassN.b b2 = new ClassN.b {
                                         b1 = A_0.GetListaLineaArco()[j] as ForseLineaClassA,
                                         c = A_0.w()[j],
                                         a = false
                                     };
                    list.Add(b2);
                }
            }
            ClassN.a comparer = new ClassN.a();
            list.Sort(comparer);
            bool flag = false;
            for (int k = 0; k < list.Count; k++)
            {
                int num6 = k + 1;
                double num7 = list[k].c.o();
                while ((num6 < list.Count) && (list[num6].c.e() < num7))
                {
                    double num8 = 0.0;
                    PuntoDueD puntoDueD = new PuntoDueD();
                    PuntoDueD x2 = new PuntoDueD();
                    bool flag2 = false;
                    if (list[k].a)
                    {
                        if (!list[num6].a && list[k].b1.MethodA(list[num6].b1, ref num8, puntoDueD, x2))
                        {
                            flag2 = true;
                        }
                    }
                    else if (list[num6].a && list[num6].b1.MethodA(list[k].b1, ref num8, puntoDueD, x2))
                    {
                        flag2 = true;
                    }
                    if (flag2 && ((num8 < A_1) || !flag))
                    {
                        flag = true;
                        A_1 = num8;
                        A_2.e(puntoDueD);
                        A_3.e(x2);
                        if (num8 == 0.0)
                        {
                            k += base.GetListaLineaArco().Count;
                            num6 += base.GetListaLineaArco().Count;
                        }
                    }
                    num6++;
                }
            }
            return flag;
        }

        private bool MathodA1(int A_0, int A_1, ref ClassN A_2, ref ClassN A_3)
        {
            A_2 = new ClassN();
            A_3 = new ClassN();
            while (A_1 < A_0)
            {
                A_1 += base.GetListaLineaArco().Count;
            }
            ClassAq classAq = new ClassAq();
            for (int i = A_0; i <= A_1; i++)
            {
                classAq.Add(this.MathodA1(i));
            }
            bool flag = A_2.MathodA1(classAq, false);
            while (A_0 < A_1)
            {
                A_0 += base.GetListaLineaArco().Count;
            }
            ClassAq aq2 = new ClassAq();
            for (int j = A_1; j <= A_0; j++)
            {
                aq2.Add(this.MathodA1(j));
            }
            bool flag2 = A_3.MathodA1(aq2, false);
            return (flag && flag2);
        }

        private ClassN MethodB()
        {
            return this.bClassN;
        }

        public void MethodB(List<PuntoDueD> A_0)
        {
            for (int i = 0; i < base.GetListaLineaArco().Count; i++)
            {
                A_0.Add(base.GetListaLineaArco()[i].h());
            }
        }

        public void MethodB(ClassN A_0)
        {
            this.e();
            base.MethodA(A_0);
            if (A_0.MethodC() != null)
            {
                this.aClassN = new ClassN();
                this.aClassN.MethodB(A_0.MethodC());
            }
            if (A_0.MethodB() != null)
            {
                this.bClassN = new ClassN();
                this.bClassN.MethodB(A_0.MethodC());
            }
        }

        public void MethodB(double A_0)
        {
            this.o();
            bool flag = this.j();
            for (int i = 0; i < base.GetListaLineaArco().Count; i++)
            {
                if (!(base.GetListaLineaArco()[i] is ForseLineaClassA))
                {
                    return;
                }
                var a = base.GetListaLineaArco()[i] as ForseLineaClassA;
                ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(a.b);
                if (flag)
                {
                    classAt.e();
                }
                else
                {
                    classAt.MethodB();
                }
                classAt.MethodA(A_0);
                a.p(classAt);
            }
            for (int j = 1; j < base.GetListaLineaArco().Count; j++)
            {
                var a2 = base.GetListaLineaArco()[j - 1] as ForseLineaClassA;
                var a3 = base.GetListaLineaArco()[j] as ForseLineaClassA;
                a2.MethodB(a3);
            }
            (base.GetListaLineaArco()[base.GetListaLineaArco().Count - 1] as ForseLineaClassA).MethodB(base.GetListaLineaArco()[0] as ForseLineaClassA);
            base.ab();
            base.y();
        }

        public bool MethodB(int A_0)
        {
            int num;
            if (A_0 == 0)
            {
                num = base.GetListaLineaArco().Count - 1;
            }
            else
            {
                num = A_0 - 1;
            }
            var a = new ForseLineaClassA(this.MathodA1(num), this.MathodA1(A_0));
            return !a.MethodB(this.MathodA1((int) (A_0 + 1)));
        }

        public bool MethodB(int A_0, int A_1)
        {
            int num = 0;
            if (A_0 == 0)
            {
                num = base.GetListaLineaArco().Count - 1;
            }
            else
            {
                num = A_0 - 1;
            }
            ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(this.MathodA1(A_0), this.MathodA1(num));
            ClassAtPuntoIncrementale at2 = new ClassAtPuntoIncrementale(this.MathodA1(A_0), this.MathodA1((int) (A_0 + 1)));
            var a = new ForseLineaClassA(this.MathodA1(A_0), this.MathodA1(A_1));
            if (at2.c(a.b) < at2.c(classAt))
            {
                a.MethodB((double) 0.99999);
                if (!base.MethodB(a))
                {
                    return true;
                }
            }
            return false;
        }

        public void MethodB(ClassN A_0, List<ClassC> A_1, ClassAg A_2)
        {
            List<PolygonalShape> list = new List<PolygonalShape>();
            base.MethodB(A_0, list, A_2);
            for (int i = 0; i < list.Count; i++)
            {
                A_1.Add(new ClassC(list[i]));
            }
        }

        public bool MethodB(ClassN A_0, ref double A_1, PuntoDueD A_2, PuntoDueD A_3)
        {
            ClassAb classAb = A_0.z();
            if (!base.z().h(classAb))
            {
                return false;
            }
            int count = base.GetListaLineaArco().Count;
            if (count != base.w().Count)
            {
                return false;
            }
            int num2 = A_0.GetListaLineaArco().Count;
            if (num2 != A_0.w().Count)
            {
                return false;
            }
            List<ClassN.b> list = new List<ClassN.b>();
            for (int i = 0; i < count; i++)
            {
                if (base.w()[i].h(classAb))
                {
                    ClassN.b item = new ClassN.b {
                                           b1 = base.GetListaLineaArco()[i] as ForseLineaClassA,
                                           c = base.w()[i],
                                           a = true
                                       };
                    list.Add(item);
                }
            }
            for (int j = 0; j < num2; j++)
            {
                if (A_0.w()[j].h(base.z()))
                {
                    ClassN.b b2 = new ClassN.b {
                                         b1 = A_0.GetListaLineaArco()[j] as ForseLineaClassA,
                                         c = A_0.w()[j],
                                         a = false
                                     };
                    list.Add(b2);
                }
            }
            ClassN.a comparer = new ClassN.a();
            list.Sort(comparer);
            bool flag = false;
            for (int k = 0; k < list.Count; k++)
            {
                int num6 = k + 1;
                double num7 = list[k].c.o();
                while ((num6 < list.Count) && (list[num6].c.e() < num7))
                {
                    double num8 = 0.0;
                    PuntoDueD puntoDueD = new PuntoDueD();
                    PuntoDueD x2 = new PuntoDueD();
                    bool flag2 = false;
                    if (list[k].a)
                    {
                        if (!list[num6].a && list[k].b1.MethodB(list[num6].b1, ref num8, puntoDueD, x2))
                        {
                            flag2 = true;
                        }
                    }
                    else if (list[num6].a && list[num6].b1.MethodB(list[k].b1, ref num8, puntoDueD, x2))
                    {
                        flag2 = true;
                    }
                    if (flag2 && ((num8 < A_1) || !flag))
                    {
                        flag = true;
                        A_1 = num8;
                        A_2.e(puntoDueD);
                        A_3.e(x2);
                        if (num8 == 0.0)
                        {
                            k += base.GetListaLineaArco().Count;
                            num6 += base.GetListaLineaArco().Count;
                        }
                    }
                    num6++;
                }
            }
            return flag;
        }

        private ClassN MethodC()
        {
            return this.aClassN;
        }

        public void MethodC(ClassN A_0)
        {
            ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale();
            if (this.MathodA1(A_0, classAt))
            {
                this.p(classAt);
            }
        }

        public void MethodC(double A_0)
        {
            this.o(A_0, this.q());
        }

        public void MethodC(ClassN A_0, List<ClassC> A_1, ClassAg A_2)
        {
            List<PolygonalShape> list = new List<PolygonalShape>();
            base.MethodC(A_0, list, A_2);
            for (int i = 0; i < list.Count; i++)
            {
                A_1.Add(new ClassC(list[i]));
            }
        }

        private bool d()
        {
            for (int i = 0; i < base.GetListaLineaArco().Count; i++)
            {
                for (int j = i + 1; j < base.GetListaLineaArco().Count; j++)
                {
                    if (base.GetListaLineaArco()[i].h().MethodB(base.GetListaLineaArco()[j].h()))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public bool d(double A_0)
        {
            this.o();
            int num = 0;
            bool flag = false;
            while ((num < base.GetListaLineaArco().Count) && (base.GetListaLineaArco().Count > 2))
            {
                int index = (num + 1) % base.GetListaLineaArco().Count;
                if (Math.Abs(ClassAd.e(base.GetListaLineaArco()[num].h(), base.GetListaLineaArco()[num].i(), base.GetListaLineaArco()[index].i())) < A_0)
                {
                    if (!(base.GetListaLineaArco()[num] is ForseLineaClassA))
                    {
                        return true;
                    }
                    (base.GetListaLineaArco()[num] as ForseLineaClassA).d(base.GetListaLineaArco()[(num + 1) % base.GetListaLineaArco().Count].i());
                    base.GetListaLineaArco().RemoveAt(index);
                    flag = true;
                }
                else
                {
                    num++;
                }
            }
            if (base.GetListaLineaArco().Count <= 2)
            {
                this.e();
                return true;
            }
            if (flag)
            {
                base.ab();
                base.y();
            }
            return false;
        }

        public void e()
        {
            this.o();
            base.e();
        }

        private bool f()
        {
            bool flag = true;
            int num = 0;
            List<PuntoDueD> list = new List<PuntoDueD>();
            while (flag && (num < 30))
            {
                num++;
                flag = false;
                for (int i = 0; i < base.GetListaLineaArco().Count; i++)
                {
                    for (int j = i + 2; j < base.GetListaLineaArco().Count; j++)
                    {
                        if (((i != 0) || (j != (base.GetListaLineaArco().Count - 1))) && (base.w()[i].e(base.w()[j]) && base.GetListaLineaArco()[i].MethodB(base.GetListaLineaArco()[j], list)))
                        {
                            int num4 = i + 1;
                            int num5 = j;
                            int num6 = (num5 - num4) / 2;
                            for (int k = 0; k <= num6; k++)
                            {
                                this.MathodA1((int) (num4 + k), (int) (num5 - k));
                            }
                            flag = true;
                        }
                    }
                }
            }
            base.y();
            return !flag;
        }

        ~ClassN()
        {
        }

        public bool j()
        {
            return (this.k() < 0.0);
        }

        public double k()
        {
            double num = 0.0;
            for (int i = 0; i < base.GetListaLineaArco().Count; i++)
            {
                PuntoDueD puntoDueD = base.GetListaLineaArco()[i].h();
                PuntoDueD x2 = base.GetListaLineaArco()[i].i();
                num += (puntoDueD.X * x2.Y) - (x2.X * puntoDueD.Y);
            }
            return (num / 2.0);
        }

        public bool l()
        {
            if (base.GetListaLineaArco().Count >= 4)
            {
                ClassAq classAq = new ClassAq();
                this.MethodB(classAq);
                ClassAq aq2 = new ClassAq();
                aq2.b(classAq);
                aq2.a(aq2[0]);
                ClassAb classAb = new ClassAb();
                aq2.a(classAb);
                classAq.c(classAb.MethodB());
                classAq.Reverse();
                ClassM classM = new ClassM();
                classM.MethodA(aq2);
                while (classAq.Count > 0)
                {
                    classM.MethodA(classAq.a((int) (classAq.Count - 1)));
                }
                classM.MethodA();
                classM.MethodB(classAq);
                classAq.RemoveAt(classAq.Count - 1);
                this.MathodA1(classAq);
                base.ab();
                if (!this.j())
                {
                    base.aa();
                }
                base.y();
                if (!this.f())
                {
                    return false;
                }
            }
            return true;
        }

        public double n()
        {
            return Math.Abs(this.k());
        }

        public void o()
        {
            this.aClassN = null;
            this.bClassN = null;
        }

        public override void o(double A_0, PuntoDueD A_1)
        {
            base.o(A_0, A_1);
            if (this.aClassN != null)
            {
                this.aClassN.o(A_0, A_1);
            }
            if (this.bClassN != null)
            {
                this.bClassN.o(A_0, A_1);
            }
        }

        public int p()
        {
            if (base.GetListaLineaArco().Count < 2)
            {
                return 0;
            }
            int num = 0;
            for (int i = 1; i < base.GetListaLineaArco().Count; i++)
            {
                if (base.GetListaLineaArco()[i].h().X < base.GetListaLineaArco()[num].h().X)
                {
                    num = i;
                }
            }
            return num;
        }

        public override void p(ClassAtPuntoIncrementale A_0)
        {
            base.p(A_0);
            if (this.aClassN != null)
            {
                this.aClassN.p(A_0);
            }
            if (this.bClassN != null)
            {
                this.bClassN.p(A_0);
            }
        }

        public PuntoDueD q()
        {
            PuntoDueD puntoDueD = new PuntoDueD(0.0, 0.0);
            double num = 0.0;
            for (int i = 0; i < base.GetListaLineaArco().Count; i++)
            {
                PuntoDueD x2 = base.GetListaLineaArco()[i].h();
                PuntoDueD x3 = base.GetListaLineaArco()[i].i();
                puntoDueD.X += (x2.X + x3.X) * ((x2.X * x3.Y) - (x3.X * x2.Y));
                puntoDueD.Y += (x2.Y + x3.Y) * ((x2.X * x3.Y) - (x3.X * x2.Y));
                num += (x2.X * x3.Y) - (x3.X * x2.Y);
            }
            num /= 2.0;
            puntoDueD.X /= 6.0 * num;
            puntoDueD.Y /= 6.0 * num;
            return puntoDueD;
        }

        public override void q(ForseLineaClassA A_0)
        {
            base.q(A_0);
            if (this.aClassN != null)
            {
                this.aClassN.q(A_0);
            }
            if (this.bClassN != null)
            {
                this.bClassN.q(A_0);
            }
        }

        public bool r()
        {
            this.aClassN = null;
            this.bClassN = null;
            int count = base.GetListaLineaArco().Count;
            if (count < 4)
            {
                return true;
            }
            bool flag = false;
            for (int i = 0; i < count; i++)
            {
                if (this.MethodB(i))
                {
                    flag = true;
                    int num3 = i + 2;
                    bool flag2 = true;
                    while (flag2)
                    {
                        if ((ClassAd.MethodA(this.MathodA1((int) (num3 - 2)), this.MathodA1((int) (num3 - 1)), this.MathodA1(num3)) && ClassAd.MethodA(this.MathodA1((int) (num3 - 1)), this.MathodA1(num3), this.MathodA1(i))) && (ClassAd.MethodA(this.MathodA1(num3), this.MathodA1(i), this.MathodA1((int) (i + 1))) && this.MethodB(i, num3)))
                        {
                            num3++;
                        }
                        else
                        {
                            num3--;
                            flag2 = false;
                        }
                    }
                    if (num3 >= (i + 2))
                    {
                        bool flag3 = this.MathodA1(i, num3, ref this.aClassN, ref this.bClassN) & this.MethodC().r();
                        return (flag3 & this.MethodB().r());
                    }
                }
            }
            if (!flag)
            {
                return true;
            }
            for (int j = (2 * count) - 1; j >= count; j--)
            {
                if (this.MethodB(j))
                {
                    flag = true;
                    int num5 = j - 2;
                    bool flag4 = true;
                    while (flag4)
                    {
                        if ((!ClassAd.MethodA(this.MathodA1((int) (num5 + 2)), this.MathodA1((int) (num5 + 1)), this.MathodA1(num5)) && !ClassAd.MethodA(this.MathodA1((int) (num5 + 1)), this.MathodA1(num5), this.MathodA1(j))) && (!ClassAd.MethodA(this.MathodA1(num5), this.MathodA1(j), this.MathodA1((int) (j - 1))) && this.MethodB(j, num5)))
                        {
                            num5--;
                        }
                        else
                        {
                            num5++;
                            flag4 = false;
                        }
                    }
                    if (num5 <= (j - 2))
                    {
                        bool flag5 = this.MathodA1(j, num5, ref this.aClassN, ref this.bClassN) & this.MethodC().r();
                        return (flag5 & this.MethodB().r());
                    }
                }
            }
            return false;
        }

        public override void r(PuntoDueD A_0)
        {
            base.r(A_0);
            if (this.aClassN != null)
            {
                this.aClassN.r(A_0);
            }
            if (this.bClassN != null)
            {
                this.bClassN.r(A_0);
            }
        }

        public void s()
        {
            this.MathodA1((double) 144.0, (double) 0.8);
        }

        public override void GetStartPoint(double A_0, PuntoDueD A_1)
        {
            base.GetStartPoint(A_0, A_1);
            if (this.aClassN != null)
            {
                this.aClassN.GetStartPoint(A_0, A_1);
            }
            if (this.bClassN != null)
            {
                this.bClassN.GetStartPoint(A_0, A_1);
            }
        }

        public bool t()
        {
            if (base.GetListaLineaArco().Count < 4)
            {
                return true;
            }
            int num = 0;
            return !this.MathodA1(ref num);
        }

        public class a : IComparer<ClassN.b>
        {
            public int Compare(ClassN.b L1, ClassN.b L2)
            {
                if (L1 == L2)
                {
                    return 0;
                }
                if (L1.c.GetEndPnt().X > L2.c.GetEndPnt().X)
                {
                    return 1;
                }
                if (L1.c.GetEndPnt().X == L2.c.GetEndPnt().X)
                {
                    return 0;
                }
                return -1;
            }
        }

        public class b
        {
            public bool a = true;
            public ForseLineaClassA b1;
            public ClassAb c;
        }
    }
}

